<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>函数参数验证</title>
</head>
<body>
  <script>
    function median(...nums) {
      return nums.sort()[Math.floor(nums.length / 2)];
    }

    const proxy = new Proxy(median, {
      apply(target, thisArg, ...argumentsList) {
        for (const arg of argumentsList) {
          if (typeof arg !== 'number') {
            throw 'Non-number argument provided';
          }
        }
        return Reflect.apply(...arguments);
      }
    });

    console.log(proxy(4, 7, 1));  // 4
    console.log(proxy(4, '7', 1));  // 4
    // Error: Non-number argument provided
  </script>
</body>
</html>